package routers

import (
	"github.com/gin-gonic/gin"

	"go-pipe/api/controller/apiv1/v1"
	"go-pipe/api/controller/apiv1/v2"
	"go-pipe/api/controller"
	"go-pipe/api/middleware/jwt"
	"github.com/swaggo/gin-swagger"
	"github.com/swaggo/gin-swagger/swaggerFiles"
	_ "github.com/swaggo/gin-swagger/example/docs"

	"go-pipe/api/middleware/cors"
	"go-pipe/api/middleware/log"
)

func InitRouter() *gin.Engine {
	r := gin.New()

	r.Use(gin.Logger())

	r.Use(gin.Recovery())
	gin.DisableConsoleColor()

	//gin.SetMode(settings.RunMode)
	gin.SetMode(gin.ReleaseMode)

	r.GET("/auth", controller.GetAuth)
	r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
	r.Use(cors.Cors())
	r.Use(log.Logger())
	apisV1 := r.Group("/api/v1")
	apisV1.Use(jwt.JWT())
	{

		apisV1.GET("/test", v1.TestApi)
		//apisV1.POST("upload", v1.Upload)

	}
	//接口不做校验
	//apisV2.Use(jwt.JWT())
	apisV2 := r.Group("/api/v2")
	{
		apisV2.GET("/test", v2.TestApi)
		apisV2.POST("/upload", v1.Upload)
		apisV2.GET("/info", v2.GetInfo)

	}

	return r
}
